﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using SPL.Entities;
using SPL.Data;

#endregion

namespace SPL.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="DetailBatchTvtProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class DetailBatchTvtProviderBaseCore : EntityProviderBase<SPL.Entities.DetailBatchTvt, SPL.Entities.DetailBatchTvtKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, SPL.Entities.DetailBatchTvtKey key)
		{
			return Delete(transactionManager, key.Id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.Int32 id)
		{
			return Delete(null, id);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="id">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.Int32 id);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_Batch key.
		///		FK_DetailBatchTVT_Batch Description: 
		/// </summary>
		/// <param name="batchId"></param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByBatchId(System.Int32 batchId)
		{
			int count = -1;
			return GetByBatchId(batchId, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_Batch key.
		///		FK_DetailBatchTVT_Batch Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="batchId"></param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		/// <remarks></remarks>
		public SPL.Entities.TList<DetailBatchTvt> GetByBatchId(TransactionManager transactionManager, System.Int32 batchId)
		{
			int count = -1;
			return GetByBatchId(transactionManager, batchId, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_Batch key.
		///		FK_DetailBatchTVT_Batch Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="batchId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByBatchId(TransactionManager transactionManager, System.Int32 batchId, int start, int pageLength)
		{
			int count = -1;
			return GetByBatchId(transactionManager, batchId, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_Batch key.
		///		fkDetailBatchTvtBatch Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="batchId"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByBatchId(System.Int32 batchId, int start, int pageLength)
		{
			int count =  -1;
			return GetByBatchId(null, batchId, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_Batch key.
		///		fkDetailBatchTvtBatch Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="batchId"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByBatchId(System.Int32 batchId, int start, int pageLength,out int count)
		{
			return GetByBatchId(null, batchId, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_Batch key.
		///		FK_DetailBatchTVT_Batch Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="batchId"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public abstract SPL.Entities.TList<DetailBatchTvt> GetByBatchId(TransactionManager transactionManager, System.Int32 batchId, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_DetailBatchTVT key.
		///		FK_DetailBatchTVT_DetailBatchTVT Description: 
		/// </summary>
		/// <param name="latest"></param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByLatest(System.Int32? latest)
		{
			int count = -1;
			return GetByLatest(latest, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_DetailBatchTVT key.
		///		FK_DetailBatchTVT_DetailBatchTVT Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="latest"></param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		/// <remarks></remarks>
		public SPL.Entities.TList<DetailBatchTvt> GetByLatest(TransactionManager transactionManager, System.Int32? latest)
		{
			int count = -1;
			return GetByLatest(transactionManager, latest, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_DetailBatchTVT key.
		///		FK_DetailBatchTVT_DetailBatchTVT Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="latest"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByLatest(TransactionManager transactionManager, System.Int32? latest, int start, int pageLength)
		{
			int count = -1;
			return GetByLatest(transactionManager, latest, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_DetailBatchTVT key.
		///		fkDetailBatchTvtDetailBatchTvt Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="latest"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByLatest(System.Int32? latest, int start, int pageLength)
		{
			int count =  -1;
			return GetByLatest(null, latest, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_DetailBatchTVT key.
		///		fkDetailBatchTvtDetailBatchTvt Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="latest"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByLatest(System.Int32? latest, int start, int pageLength,out int count)
		{
			return GetByLatest(null, latest, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_DetailBatchTVT key.
		///		FK_DetailBatchTVT_DetailBatchTVT Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="latest"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public abstract SPL.Entities.TList<DetailBatchTvt> GetByLatest(TransactionManager transactionManager, System.Int32? latest, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_User key.
		///		FK_DetailBatchTVT_User Description: 
		/// </summary>
		/// <param name="createdBy"></param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByCreatedBy(System.Int32 createdBy)
		{
			int count = -1;
			return GetByCreatedBy(createdBy, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_User key.
		///		FK_DetailBatchTVT_User Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="createdBy"></param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		/// <remarks></remarks>
		public SPL.Entities.TList<DetailBatchTvt> GetByCreatedBy(TransactionManager transactionManager, System.Int32 createdBy)
		{
			int count = -1;
			return GetByCreatedBy(transactionManager, createdBy, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_User key.
		///		FK_DetailBatchTVT_User Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="createdBy"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByCreatedBy(TransactionManager transactionManager, System.Int32 createdBy, int start, int pageLength)
		{
			int count = -1;
			return GetByCreatedBy(transactionManager, createdBy, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_User key.
		///		fkDetailBatchTvtUser Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="createdBy"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByCreatedBy(System.Int32 createdBy, int start, int pageLength)
		{
			int count =  -1;
			return GetByCreatedBy(null, createdBy, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_User key.
		///		fkDetailBatchTvtUser Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="createdBy"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public SPL.Entities.TList<DetailBatchTvt> GetByCreatedBy(System.Int32 createdBy, int start, int pageLength,out int count)
		{
			return GetByCreatedBy(null, createdBy, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_DetailBatchTVT_User key.
		///		FK_DetailBatchTVT_User Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="createdBy"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of SPL.Entities.DetailBatchTvt objects.</returns>
		public abstract SPL.Entities.TList<DetailBatchTvt> GetByCreatedBy(TransactionManager transactionManager, System.Int32 createdBy, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override SPL.Entities.DetailBatchTvt Get(TransactionManager transactionManager, SPL.Entities.DetailBatchTvtKey key, int start, int pageLength)
		{
			return GetById(transactionManager, key.Id, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_DetailBatchTVT index.
		/// </summary>
		/// <param name="id"></param>
		/// <returns>Returns an instance of the <see cref="SPL.Entities.DetailBatchTvt"/> class.</returns>
		public SPL.Entities.DetailBatchTvt GetById(System.Int32 id)
		{
			int count = -1;
			return GetById(null,id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DetailBatchTVT index.
		/// </summary>
		/// <param name="id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SPL.Entities.DetailBatchTvt"/> class.</returns>
		public SPL.Entities.DetailBatchTvt GetById(System.Int32 id, int start, int pageLength)
		{
			int count = -1;
			return GetById(null, id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DetailBatchTVT index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="id"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SPL.Entities.DetailBatchTvt"/> class.</returns>
		public SPL.Entities.DetailBatchTvt GetById(TransactionManager transactionManager, System.Int32 id)
		{
			int count = -1;
			return GetById(transactionManager, id, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DetailBatchTVT index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SPL.Entities.DetailBatchTvt"/> class.</returns>
		public SPL.Entities.DetailBatchTvt GetById(TransactionManager transactionManager, System.Int32 id, int start, int pageLength)
		{
			int count = -1;
			return GetById(transactionManager, id, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DetailBatchTVT index.
		/// </summary>
		/// <param name="id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="SPL.Entities.DetailBatchTvt"/> class.</returns>
		public SPL.Entities.DetailBatchTvt GetById(System.Int32 id, int start, int pageLength, out int count)
		{
			return GetById(null, id, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_DetailBatchTVT index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="id"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="SPL.Entities.DetailBatchTvt"/> class.</returns>
		public abstract SPL.Entities.DetailBatchTvt GetById(TransactionManager transactionManager, System.Int32 id, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a SPL.Entities.TList&lt;DetailBatchTvt&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="SPL.Entities.TList&lt;DetailBatchTvt&gt;"/></returns>
		public static SPL.Entities.TList<DetailBatchTvt> Fill(IDataReader reader, SPL.Entities.TList<DetailBatchTvt> rows, int start, int pageLength)
		{
		// advance to the starting row
		for (int i = 0; i < start; i++)
		{
			if (!reader.Read())
			return rows; // not enough rows, just return
		}
		for (int i = 0; i < pageLength; i++)
		{
			if (!reader.Read())
			break; // we are done
			string key = null;
			
			SPL.Entities.DetailBatchTvt c = null;
			if (DataRepository.Provider.UseEntityFactory)
			{
			key = new System.Text.StringBuilder("DetailBatchTvt")
			.Append("|").Append((reader.IsDBNull(((int)SPL.Entities.DetailBatchTvtColumn.Id - 1))?(int)0:(System.Int32)reader[((int)SPL.Entities.DetailBatchTvtColumn.Id - 1)]).ToString()).ToString();
			c = EntityManager.LocateOrCreate<DetailBatchTvt>(
			key.ToString(), // EntityTrackingKey
			"DetailBatchTvt",  //Creational Type
			DataRepository.Provider.EntityCreationalFactoryType,  //Factory used to create entity
			DataRepository.Provider.EnableEntityTracking); // Track this entity?
			}
			else
			{
			c = new SPL.Entities.DetailBatchTvt();
			}
			
			if (!DataRepository.Provider.EnableEntityTracking ||
			c.EntityState == EntityState.Added ||
			(DataRepository.Provider.EnableEntityTracking &&
			((DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
			(DataRepository.Provider.CurrentLoadPolicy == LoadPolicy.DiscardChanges && (c.EntityState == EntityState.Unchanged ||
								c.EntityState == EntityState.Changed)))))
						{
			c.SuppressEntityEvents = true;
			c.Id = (System.Int32)reader["Id"];
			c.BatchId = (System.Int32)reader["BatchId"];
			c.Me1 = (System.Int32)reader["ME1"];
			c.Me2 = (System.Int32)reader["ME2"];
			c.IsStop = (System.Boolean)reader["IsStop"];
			c.CreatedBy = (System.Int32)reader["CreatedBy"];
			c.CreatedAt = (System.DateTime)reader["CreatedAt"];
			c.InputTime = (System.DateTime)reader["InputTime"];
			c.Latest = reader.IsDBNull(reader.GetOrdinal("Latest")) ? null : (System.Int32?)reader["Latest"];
			c.EntityTrackingKey = key;
			c.AcceptChanges();
			c.SuppressEntityEvents = false;
			}
			rows.Add(c);
		}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="SPL.Entities.DetailBatchTvt"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="SPL.Entities.DetailBatchTvt"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, SPL.Entities.DetailBatchTvt entity)
		{
			if (!reader.Read()) return;
			
			entity.Id = (System.Int32)reader["Id"];
			entity.BatchId = (System.Int32)reader["BatchId"];
			entity.Me1 = (System.Int32)reader["ME1"];
			entity.Me2 = (System.Int32)reader["ME2"];
			entity.IsStop = (System.Boolean)reader["IsStop"];
			entity.CreatedBy = (System.Int32)reader["CreatedBy"];
			entity.CreatedAt = (System.DateTime)reader["CreatedAt"];
			entity.InputTime = (System.DateTime)reader["InputTime"];
			entity.Latest = reader.IsDBNull(reader.GetOrdinal("Latest")) ? null : (System.Int32?)reader["Latest"];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="SPL.Entities.DetailBatchTvt"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="SPL.Entities.DetailBatchTvt"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, SPL.Entities.DetailBatchTvt entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.Id = (System.Int32)dataRow["Id"];
			entity.BatchId = (System.Int32)dataRow["BatchId"];
			entity.Me1 = (System.Int32)dataRow["ME1"];
			entity.Me2 = (System.Int32)dataRow["ME2"];
			entity.IsStop = (System.Boolean)dataRow["IsStop"];
			entity.CreatedBy = (System.Int32)dataRow["CreatedBy"];
			entity.CreatedAt = (System.DateTime)dataRow["CreatedAt"];
			entity.InputTime = (System.DateTime)dataRow["InputTime"];
			entity.Latest = Convert.IsDBNull(dataRow["Latest"]) ? null : (System.Int32?)dataRow["Latest"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="SPL.Entities.DetailBatchTvt"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">SPL.Entities.DetailBatchTvt Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		internal override void DeepLoad(TransactionManager transactionManager, SPL.Entities.DetailBatchTvt entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region BatchIdSource	
			if (CanDeepLoad(entity, "Batch|BatchIdSource", deepLoadType, innerList) 
				&& entity.BatchIdSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.BatchId;
				Batch tmpEntity = EntityManager.LocateEntity<Batch>(EntityLocator.ConstructKeyFromPkItems(typeof(Batch), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.BatchIdSource = tmpEntity;
				else
					entity.BatchIdSource = DataRepository.BatchProvider.GetById(transactionManager, entity.BatchId);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'BatchIdSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.BatchIdSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.BatchProvider.DeepLoad(transactionManager, entity.BatchIdSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion BatchIdSource

			#region LatestSource	
			if (CanDeepLoad(entity, "DetailBatchTvt|LatestSource", deepLoadType, innerList) 
				&& entity.LatestSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.Latest ?? (int)0);
				DetailBatchTvt tmpEntity = EntityManager.LocateEntity<DetailBatchTvt>(EntityLocator.ConstructKeyFromPkItems(typeof(DetailBatchTvt), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.LatestSource = tmpEntity;
				else
					entity.LatestSource = DataRepository.DetailBatchTvtProvider.GetById(transactionManager, (entity.Latest ?? (int)0));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'LatestSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.LatestSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.DetailBatchTvtProvider.DeepLoad(transactionManager, entity.LatestSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion LatestSource

			#region CreatedBySource	
			if (CanDeepLoad(entity, "User|CreatedBySource", deepLoadType, innerList) 
				&& entity.CreatedBySource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.CreatedBy;
				User tmpEntity = EntityManager.LocateEntity<User>(EntityLocator.ConstructKeyFromPkItems(typeof(User), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.CreatedBySource = tmpEntity;
				else
					entity.CreatedBySource = DataRepository.UserProvider.GetById(transactionManager, entity.CreatedBy);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CreatedBySource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CreatedBySource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.UserProvider.DeepLoad(transactionManager, entity.CreatedBySource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion CreatedBySource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetById methods when available
			
			#region DetailBatchTvtCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<DetailBatchTvt>|DetailBatchTvtCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'DetailBatchTvtCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.DetailBatchTvtCollection = DataRepository.DetailBatchTvtProvider.GetByLatest(transactionManager, entity.Id);

				if (deep && entity.DetailBatchTvtCollection.Count > 0)
				{
					deepHandles.Add("DetailBatchTvtCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<DetailBatchTvt>) DataRepository.DetailBatchTvtProvider.DeepLoad,
						new object[] { transactionManager, entity.DetailBatchTvtCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the SPL.Entities.DetailBatchTvt object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">SPL.Entities.DetailBatchTvt instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">SPL.Entities.DetailBatchTvt Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		internal override bool DeepSave(TransactionManager transactionManager, SPL.Entities.DetailBatchTvt entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region BatchIdSource
			if (CanDeepSave(entity, "Batch|BatchIdSource", deepSaveType, innerList) 
				&& entity.BatchIdSource != null)
			{
				DataRepository.BatchProvider.Save(transactionManager, entity.BatchIdSource);
				entity.BatchId = entity.BatchIdSource.Id;
			}
			#endregion 
			
			#region LatestSource
			if (CanDeepSave(entity, "DetailBatchTvt|LatestSource", deepSaveType, innerList) 
				&& entity.LatestSource != null)
			{
				DataRepository.DetailBatchTvtProvider.Save(transactionManager, entity.LatestSource);
				entity.Latest = entity.LatestSource.Id;
			}
			#endregion 
			
			#region CreatedBySource
			if (CanDeepSave(entity, "User|CreatedBySource", deepSaveType, innerList) 
				&& entity.CreatedBySource != null)
			{
				DataRepository.UserProvider.Save(transactionManager, entity.CreatedBySource);
				entity.CreatedBy = entity.CreatedBySource.Id;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<Delegate, object> deepHandles = new Dictionary<Delegate, object>();
	
			#region List<DetailBatchTvt>
				if (CanDeepSave(entity.DetailBatchTvtCollection, "List<DetailBatchTvt>|DetailBatchTvtCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(DetailBatchTvt child in entity.DetailBatchTvtCollection)
					{
						if(child.LatestSource != null)
							child.Latest = child.LatestSource.Id;
						else
							child.Latest = entity.Id;

					}

					if (entity.DetailBatchTvtCollection.Count > 0 || entity.DetailBatchTvtCollection.DeletedItems.Count > 0)
					{
						DataRepository.DetailBatchTvtProvider.Save(transactionManager, entity.DetailBatchTvtCollection);
						
						deepHandles.Add(
							(DeepSaveHandle< DetailBatchTvt >) DataRepository.DetailBatchTvtProvider.DeepSave,
							new object[] { transactionManager, entity.DetailBatchTvtCollection, deepSaveType, childTypes, innerList }
						);
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region DetailBatchTvtChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>SPL.Entities.DetailBatchTvt</c>
	///</summary>
	public enum DetailBatchTvtChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Batch</c> at BatchIdSource
		///</summary>
		[ChildEntityType(typeof(Batch))]
		Batch,
			
		///<summary>
		/// Composite Property for <c>DetailBatchTvt</c> at LatestSource
		///</summary>
		[ChildEntityType(typeof(DetailBatchTvt))]
		DetailBatchTvt,
			
		///<summary>
		/// Composite Property for <c>User</c> at CreatedBySource
		///</summary>
		[ChildEntityType(typeof(User))]
		User,
	
		///<summary>
		/// Collection of <c>DetailBatchTvt</c> as OneToMany for DetailBatchTvtCollection
		///</summary>
		[ChildEntityType(typeof(TList<DetailBatchTvt>))]
		DetailBatchTvtCollection,
	}
	
	#endregion DetailBatchTvtChildEntityTypes
	
	#region DetailBatchTvtFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;DetailBatchTvtColumn&gt;"/> class
	/// that is used exclusively with a <see cref="DetailBatchTvt"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class DetailBatchTvtFilterBuilder : SqlFilterBuilder<DetailBatchTvtColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DetailBatchTvtFilterBuilder class.
		/// </summary>
		public DetailBatchTvtFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the DetailBatchTvtFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public DetailBatchTvtFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the DetailBatchTvtFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public DetailBatchTvtFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion DetailBatchTvtFilterBuilder
	
	#region DetailBatchTvtParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;DetailBatchTvtColumn&gt;"/> class
	/// that is used exclusively with a <see cref="DetailBatchTvt"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class DetailBatchTvtParameterBuilder : ParameterizedSqlFilterBuilder<DetailBatchTvtColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the DetailBatchTvtParameterBuilder class.
		/// </summary>
		public DetailBatchTvtParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the DetailBatchTvtParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public DetailBatchTvtParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the DetailBatchTvtParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public DetailBatchTvtParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion DetailBatchTvtParameterBuilder
} // end namespace
